package com.itheima;

public class ArrayDemo1 {
    public static void main(String[] args) {
        randomCall();
    }

    //我是一名java初学者，请帮我开发一个随机点名的方法，假设我们有10名学生
    public static void randomCall(){
        //1.定义一个静态数组(简写),存储10个学生姓名
        //String[] names={"小王","小张","小李","小赵","小钱","小孙","小李","小苏","小秦","小小};
        //数组名其实存储的是地址
        //完整写法
        String[] names=new String[]{"小王","小张","小李","小赵","小钱","小孙","小李","小苏","小秦","小小"};

        //2.随机获取一个索引值
        //Math.random()随机获取的是[0,1)的值
        //name.length=10    [0,10),即0-9都可以选到
        int index=(int)(Math.random() * names.length);

        //3.根据索引,获取数据中的元素
        String name=names[index];
        System.out.println(name);
    }
}
